import numpy as np
from matplotlib import pyplot as plt, axes, font_manager
import matplotlib

Zh_Font = matplotlib.font_manager.FontProperties(fname="../venv/include/SourceHanSansSC-Bold.otf")
plt.rc('font', family='Times New Roman')
plt.rc('font', size=100)
plt.rc('font', weight='bold')
legend_font = {
    'fname': 'C:/Windows/fonts/simhei.ttf',  # 引用系统字体
    'style': 'normal',
    'size': 40,  # 字号
    'weight': "bold",  # 是否加粗，不加粗
}

import random

# 迭代次数 200     时间区间 80

# 1、设置数据
x_name = ['项目 1', '项目 2', '项目 3']
y_1 = [0.6, 0.7, 0.6]
y_2 = [0.8, 0.8, 0.8]
y_3 = [0.5, 0.4, 0.6]
y_4 = [0.7, 0.6, 0.7]
# 2、创建画布
plt.figure(figsize=(60, 30))

# 3、绘制柱状图
x_ticks = np.arange(3) + 2
plt.bar(x_ticks, y_1, width=0.15, label='工期-本算法', color='#3300FF')  # 间距 0.03
plt.bar([i + 0.18 for i in x_ticks], y_2, width=0.15, label='工期-企业', color='#0066FF')
plt.bar([i + 0.36 for i in x_ticks], y_3, width=0.15, label='成本-本算法', color='#484848')
plt.bar([i + 0.54 for i in x_ticks], y_4, width=0.15, label='成本-企业', color='#A8A8A8')
plt.legend(prop=legend_font, bbox_to_anchor=(1, 0), loc=6)

# 4、修改X刻度
plt.yticks(fontsize=100, fontproperties=Zh_Font)
plt.xticks(np.arange(3) + 2.3, x_name, fontsize=100, fontproperties=Zh_Font)
plt.ylabel('解的质量', fontsize=90, fontproperties=Zh_Font)
plt.xlabel('项目', fontsize=90, fontproperties=Zh_Font)
# 5、标题
plt.title("解的质量评价对比图", fontsize=100, fontproperties=Zh_Font)
plt.show()
